home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / INTERRUP.SWG / 0012_Hooking an Interrupt.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  3KB  |  88 lines

  1. {
  2. CHRIS LAUTENBACH
  3.  
  4. ║ I understand basically what you're saying - have a TSR/ISR define
  5. ║ Variables Within itself, then have any child processes hook into those
  6. ║ Variables via an interupt inquiry. However, I'm still a bit fuzzy on it.
  7. ║ Could you provide an example, or a better definition?
  8.  
  9.     Here's an example of how to hook an interrupt....
  10. }
  11.  
  12. Unit ExampleInt;  { Interrupt hooker example }
  13.  
  14. { Written 08/15/93 by Chris Lautenbach.  Released to the public domain.     }
  15.  
  16. { This Unit, when placed in the Uses clause of your main Program, will hook }
  17. { Dos Interrupt 28h (Dos Idle) which is called by Dos when it isn't busy.   }
  18. { Under normal circumstances, this will produce a sort of 'multitasking'    }
  19. { effect when Dos calls it.  Make sure you call the NotBusy Procedure in    }
  20. { any keyboard wait loops -- or any other loop that continues For a While,  }
  21. { otherwise Dos will not get a chance to service Int 28h.                   }
  22.  
  23. { In addition to hooking Int28h, it also provides a custom Exit Procedure   }
  24. { to deactivate the interrupt.  In this manner, this Unit can be totally    }
  25. { transparent to the Program it is included in -- even if the Program       }
  26. { terminates With an error, the interrupt is always disconnected.           }
  27.  
  28. { Access to IntStart and IntStop are provided thru the Interface section to }
  29. { allow disabling of the interrupt -- in Case a Dos shell or similar        }
  30. { operation is required.                                                    }
  31.  
  32. Interface
  33.  
  34. Uses
  35.   Dos, Crt;
  36.  
  37. Procedure IntStart;                         { Hook interrupt 28h - internal }
  38. Procedure IntStop;                        { Unhook interrupt 28h - internal }
  39. Procedure NotBusy; Inline($CD/$28);           { Call the Dos Idle interrupt }
  40.  
  41. Var
  42.   Int28Orig,
  43.   OldExitProc : Pointer;
  44.  
  45. Implementation
  46.  
  47. Procedure JmpOldISR(OldISR : Pointer);                 { Jump to an old ISR }
  48. Inline ($5B/$58/$87/$5E/$0E/$87/$46/$10/$89/
  49.         $EC/$5D/$07/$1F/$5F/$5E/$5A/$59/$CB);
  50.  
  51. {$F+}
  52. Procedure Int28Handler(Flags,CS,IP,AX,BX,CX,DX,SI,DI,DS,ES,BP:Word);interrupt;
  53. begin
  54.   Inline($FA);                                        { Turn interrupts off }
  55.  
  56.   { ... your code goes here ... }
  57.  
  58.   Inline($FB);                                    { Turn interrupts back on }
  59.   JmpOldIsr(Int28Orig);            { Jump to the original interrupt address }
  60. end;
  61. {$F-}
  62.  
  63. Procedure IntStart;
  64. begin
  65.   GetIntVec($28, Int28Orig);                  { Save original Int 28 vector }
  66.   SetIntVec($28, @Int28Handler);       { Install our cool new Int 28 vector }
  67. end;
  68.  
  69. {$F+}
  70. Procedure IntStop;
  71. begin
  72.   SetIntVec($28, Int28Orig);                       { Restore Int 28 handler }
  73. end;
  74.  
  75. Procedure IntExit;
  76. begin
  77.   ExitProc := OldExitProc;                     { Restore old Exit Procedure }
  78.   IntStop;                                       { Deactivate our interrupt }
  79. end;
  80. {$F-}
  81.  
  82. begin
  83.   OldExitProc := ExitProc;                     { Save the current Exit proc }
  84.   ExitProc := @IntExit;                         { Install our new Exit proc }
  85.   IntStart;                                      { Initialize our interrupt }
  86. end.
  87.  
  88.